package com.kotiln.lgc.lib_voice.weakup

import android.content.Context
import android.util.Log
import com.baidu.speech.EventListener
import com.baidu.speech.EventManager
import com.baidu.speech.EventManagerFactory
import com.baidu.speech.asr.SpeechConstant
import org.json.JSONObject

/**
 *@fileName VoickWeakUp
 *@date2021/1/20  15:28
 *@author VoickWeakUp$
 *@describe TODO
 *@desc 语音唤醒
 */
object VoiceWakeUp {

    //启动数据
    private lateinit var wakeUpJson:String

    //唤醒对象
    private lateinit var wp:EventManager

    //初始化唤醒
    fun initWakeUp(mContext: Context, listener: EventListener){
        Log.i("VoiceManager","wakeup init")
        val map = HashMap<Any, Any>()
        //本地文件路径
        map[SpeechConstant.WP_WORDS_FILE] = "assets:///WakeUp.bin"
        //是否获取音量
        map[SpeechConstant.ACCEPT_AUDIO_VOLUME]=false
        //Map转换成json
        wakeUpJson=JSONObject(map as Map<Any,Any>).toString()

        //设置监听器
        wp=EventManagerFactory.create(mContext,"wp")
        wp.registerListener(listener)

        //默认启动
        startWeakUp()
    }

    //启动唤醒
    fun startWeakUp(){
        Log.i("VoiceManager", wakeUpJson)
        wp.send(SpeechConstant.WAKEUP_START, wakeUpJson,null,0,0)
    }

    //停止唤醒
    fun stopWeakUp(){
        wp.send(SpeechConstant.WAKEUP_STOP, null,null,0,0)
    }

    //销毁唤醒
    fun realeaseWeakUp(){}

}